package com.tn.rtdata.examples.stockticker.server.fill;

import java.util.Map;

import com.tn.openrpc.util.FactoryException;
import com.tn.openrpc.util.ParametrizedFactory;
import com.tn.rtdata.DataEventStats;
import com.tn.rtdata.Fill;
import com.tn.rtdata.FillIdentity;
import com.tn.rtdata.FillInfo;
import com.tn.rtdata.examples.stockticker.StockTick;
import com.tn.rtdata.util.ObservableMap;

/**
 * An implementation of <code>ParametrizedFactory</code> that creates a <code>StockTickFill</code>.
 */
public class StockTickFillFactory implements ParametrizedFactory<Fill, FillIdentity>
{
  private ObservableMap<String, StockTick> entryCache;
  private Map<FillIdentity, FillInfo<String, StockTick>> fillInfoCache;
  private Map<String, DataEventStats> dataEventStatsCache;

  /**
   * Creates a new <code>StockTickFillFactory</code> initialized with caches each <code>StockTickFill</code> needs.
   */
  public StockTickFillFactory(
    ObservableMap<String, StockTick> entryCache,
    Map<FillIdentity, FillInfo<String, StockTick>> fillInfoCache,
    Map<String, DataEventStats> dataEventStatsCache
  )
  {
    this.entryCache = entryCache;
    this.fillInfoCache = fillInfoCache;
    this.dataEventStatsCache = dataEventStatsCache;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public Fill newInstance(FillIdentity fillIdentity) throws FactoryException
  {
    return new StockTickFill(fillIdentity, entryCache, fillInfoCache, dataEventStatsCache);
  }
}
